Spatial analysis of oil spills in California

Use of an interactive map

Janelle C true
2021-02-17

Interactive Map

hide
oil_spill <- read_sf(here("_posts","2021-03-13-spatial-analysis-of-oil-spills-in-california", "data"), layer = "ds394") %>% 
  clean_names()

ca_counties <- read_sf(here("_posts","2021-03-13-spatial-analysis-of-oil-spills-in-california","ca_counties"), layer = "CA_Counties_TIGER2016") %>% 
  clean_names()

# st_crs(oil_spill)

# st_crs(ca_counties)

oil_spill <- st_transform(oil_spill, st_crs(ca_counties)) 

oil_spill_duplicate <- oil_spill %>% 
  get_dupes(latitude, longitude)

# st_crs(oil_spill)

tmap_mode("view")

tm_shape(oil_spill) +
  tm_dots(aes(color = "#700e01")) +
  tm_basemap("Esri.NatGeoWorldMap")

Figure 1. Map of oil spills in California in 2008. Each dot represents one location of an oil spill.

Oil spills by county

hide
oil_count <- oil_spill %>% 
  count(localecoun)

oil_count_join <- ca_counties %>% 
  st_join(oil_count)

ggplot(oil_count_join) +
  geom_sf(aes(fill = n)) +
  theme_void() +
  scale_fill_gradientn(colors = c("mistyrose1","lightsalmon3", "lightsalmon4")) +
  labs(fill = "Number of Oil Spills") +
  annotation_scale(pad_x = unit(2, "cm"), aes(unit_category = "imperial", style = "bar")) +
  annotation_north_arrow(height = unit(1.5, "cm"), width = unit(1.5, "cm"), style = north_arrow_nautical())
Figure 2. Oil spill counts by county in 2008. Darker colored counties had higher numbers of oil spills and counties with no data are shown in grey.

Figure 1: Figure 2. Oil spill counts by county in 2008. Darker colored counties had higher numbers of oil spills and counties with no data are shown in grey.